﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//f(11)返回4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class SolGoodFeature233
{
    IList<int> res;
    public IList<int> Circle(int[][] martix)
    {
     
        res= new List<int>();

        int rowNum=martix.Length;
        int colNum=martix[0].Length;

        DFS(martix, 0, colNum-1, 0, rowNum-1);


        return res;
    }
  public void  DFS(int[][] martix,int left, int right, int top, int bottom)
    {

        if (left <= right && top <= bottom) {


            for (int i = left; i <= right; i++) {

                res.Add(martix[top][i]);
                //Console.WriteLine(martix[top][i]);

            }

            for (int i = top+1; i <= bottom; i++)
            {

                res.Add(martix[i][right]);
                //Console.WriteLine(martix[i][right]);

            }

            if (left < right && top < bottom)//相等的时候不执行
            {

                for (int i = right-1; i >left; i--)
                {

                    res.Add(martix[bottom][i]);
                   // Console.WriteLine(martix[bottom][i]);

                }

                for (int i = bottom; i > top; i--)
                {

                    res.Add(martix[i][left]);

                    //Console.WriteLine(martix[i][left]);
                }


            }
            DFS(martix, left+1, right-1, top+1, bottom-1);
        }




    }

}

//输入例子：

//5 6 1 2 3 4 5 6
//18 19 20 21 22 7
//17 28 29 30 23 8
//16 27 26 25 24 9
//15 14 13 12 11 10
class ProgramGoodFeature233
{



    static void MainGoodFeature233()
    {

        


        
       
        string s;
        s = Console.ReadLine();
        string[] tokens1 = s.Split(' ');
        int rowNum = int.Parse(tokens1[0]);
        int colNum = int.Parse(tokens1[1]);

        int[][] martix = new int[rowNum][];



        for (int i = 0; i < rowNum; i++)
        {
            martix[i] = new int[colNum];

        }
        for (int i = 2; i < tokens1.Length; i++)
        {
            martix[0][i-2] = int.Parse(tokens1[i]);//初始化第一行
        }

        int rowINdex = 1;
        //while ((s = Console.ReadLine()) != null) {
            while ((s = System.Console.ReadLine()) != null)
            {

                Console.WriteLine(s);
            string[] tokens = s.Split(' ');
            for (int i = 0; i < tokens.Length; i++)
            {
                martix[rowINdex][i] = int.Parse(tokens[i]);
            }
            rowINdex++;
        }

       //for (int i = 0;i < martix.Length; i++)
       // {
       //     for(int j = 0;j < martix[i].Length; j++)
       //     {
       //         Console.Write("     "+martix[i][j]);
       //     }
       //     Console.WriteLine();
       // }

        SolGoodFeature233 sol = new SolGoodFeature233();
        IList<int> res = sol.Circle(martix);
        for(int i = 0; i < res.Count; i++)
        {
            Console.WriteLine(res[i]);
        }




    }
}

